package com.yy.jhl.ui.manager.presenter;

import com.google.gson.Gson;
import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.bean.InviteBatchInfo;
import com.yy.jhl.bean.InvitePackageInfo;
import com.yy.jhl.bean.ProjectInfo;
import com.yy.jhl.ui.manager.contract.MainWithCodeContract;

import okhttp3.ResponseBody;

/**
 * Created by libingn on 2017/12/18.
 */

public class MainWithCodePresenter extends MainWithCodeContract.Presenter {
    @Override
    public void getBatchCode() {
        mRxManage.addSubscription(Api.getDefault().getInviteBatch(), new RxSubscriber<ResponseBody>(mContext,false) {
            @Override
            protected void _onNext(String result) {
                InviteBatchInfo projectInfo = new Gson().fromJson(result,InviteBatchInfo.class);
                mView.getBatchCodeSuccess(projectInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getBatchCodeFail();
            }
        });
    }

    @Override
    public void getPackageInfo(String id) {
        mRxManage.addSubscription(Api.getDefault().getInvitePackage(id), new RxSubscriber<ResponseBody>(mContext,true) {
            @Override
            protected void _onNext(String result) {
                InvitePackageInfo projectInfo = new Gson().fromJson(result,InvitePackageInfo.class);
                mView.getPackageInfoSuccess(projectInfo);
            }

            @Override
            protected void _onError(String message) {
                mView.getPackageInfoFail();
            }
        });
    }
}
